package com.cskaoyan.factory;

import com.cskaoyan.bean.*;

public class AnimalFactory {

    //方法名任意写
    public Animal createAnimal(String name) {
        if ("pig".equals(name)) {
            return new Pig();
        }
        if ("chicken".equals(name)) {
            return new Chicken();
        }
        if ("duck".equals(name)) {
            return new Duck();
        }
        if ("sheep".equals(name)) { //开闭原则
            return new Sheep();
        }
        return null;
    }
}
